package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class ArrayDProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static ArrayDProduction instance = new ArrayDProduction();

    public static ArrayDProduction getInstance() {
        return instance;
    }


    /**
     * Regra: array : '[' expr_arit? ']';
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (!basicParse(st, TokenClass.DELIMITER_OPENING_SQUARE_BRACKET)) {
            return false;
        }
        ExprAritProduction.getInstance().analyze(st, et);
        if (!basicParse(st, TokenClass.DELIMITER_CLOSING_SQUARE_BRACKET)) {
            return skipUntilSynchronize(st, et, "Era esperado um ']'");
        }

        return true;
    }

    @Override
    protected void populateFirst() {
        first.add(TokenClass.DELIMITER_OPENING_SQUARE_BRACKET);
    }

    @Override
    protected void populateFollow() {

        //from declrvar.follow
        follow.add(TokenClass.OPERATOR_ASSIGNMENT);
        follow.add(TokenClass.DELIMITER_COMMA);
        follow.add(TokenClass.DELIMITER_SEMICOLON);
        follow.add(TokenClass.DELIMITER_COMMA);
        follow.add(TokenClass.DELIMITER_SEMICOLON);
        follow.add(TokenClass.DELIMITER_CLOSING_PARENTHESIS);


        follow.add(TokenClass.DELIMITER_OPENING_SQUARE_BRACKET);
    }

    
}
